package com.longge;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.stream.Collectors;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-06-02 22:18
 */
public class GetImportance {
    public int getImportance(List<Employee> employees, int id) {

        LinkedList<Employee> queue = new LinkedList<>();
        Employee root = employees.stream().filter(employee -> employee.id == id).findFirst().get();
        queue.add(root);
        employees.remove(root);
        int res = 0;
        while (!queue.isEmpty()){
            Employee e = queue.poll();
            res+=e.importance;
            List<Employee> col = employees.stream().filter(employee -> e.subordinates.contains(employee.id)).collect(Collectors.toList());
            employees.removeAll(col);
            queue.addAll(col);
        }
        return res;
    }
}
